package com.ityangxu.langchain4j.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ityangxu.langchain4j.entity.*;
import com.ityangxu.langchain4j.mapper.PetsMapper;

import com.ityangxu.langchain4j.service.PetsService;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class PetsServiceImpl extends ServiceImpl<PetsMapper, Pets> implements PetsService {
    @Resource
    private PetsMapper petsMapper;

    @Override
    public Result<IPage<Pets>> getPetsList(PetsDto petsDto) {
        LambdaQueryWrapper<Pets> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .eq(petsDto.getName() != null && petsDto.getName() != "", Pets::getName, petsDto.getName())
                .eq(petsDto.getOwnerName() != null && petsDto.getOwnerName() != "", Pets::getGender, petsDto.getOwnerName())
                .between(petsDto.getEnd_time() != null && petsDto.getStart_time() != null, Pets::getCreatedAt, petsDto.getStart_time(), petsDto.getEnd_time());

        Page<Pets> page = new Page<>(petsDto.getCurrent_page(), petsDto.getPage_size());
        IPage<Pets> petsPage = this.page(page, lambdaQueryWrapper);
        return Result.success(petsPage);
    }

}
